home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / GNU / emacs.inst / emacs19.idb / usr / gnu / info / elisp-7.z / elisp-7
Encoding:
GNU Info File  |  1994-08-02  |  49.0 KB  |  1,236 lines

  1. This is Info file elisp, produced by Makeinfo-1.55 from the input file
  2. elisp.texi.
  3.  
  4.    This version is newer than the second printed edition of the GNU
  5. Emacs Lisp Reference Manual.  It corresponds to Emacs Version 19.19.
  6.  
  7.    Published by the Free Software Foundation 675 Massachusetts Avenue
  8. Cambridge, MA 02139 USA
  9.  
  10.    Copyright (C) 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
  11.  
  12.    Permission is granted to make and distribute verbatim copies of this
  13. manual provided the copyright notice and this permission notice are
  14. preserved on all copies.
  15.  
  16.    Permission is granted to copy and distribute modified versions of
  17. this manual under the conditions for verbatim copying, provided that
  18. the entire resulting derived work is distributed under the terms of a
  19. permission notice identical to this one.
  20.  
  21.    Permission is granted to copy and distribute translations of this
  22. manual into another language, under the above conditions for modified
  23. versions, except that this permission notice may be stated in a
  24. translation approved by the Foundation.
  25.  
  26.    Permission is granted to copy and distribute modified versions of
  27. this manual under the conditions for verbatim copying, provided also
  28. that the section entitled "GNU Emacs General Public License" is included
  29. exactly as in the original, and provided that the entire resulting
  30. derived work is distributed under the terms of a permission notice
  31. identical to this one.
  32.  
  33.    Permission is granted to copy and distribute translations of this
  34. manual into another language, under the above conditions for modified
  35. versions, except that the section entitled "GNU Emacs General Public
  36. License" may be included in a translation approved by the Free Software
  37. Foundation instead of in the original English.
  38.  
  39. 
  40. File: elisp,  Node: Sequencing,  Next: Conditionals,  Up: Control Structures
  41.  
  42. Sequencing
  43. ==========
  44.  
  45.    Evaluating forms in the order they are written is the most common
  46. control structure.  Sometimes this happens automatically, such as in a
  47. function body.  Elsewhere you must use a control structure construct to
  48. do this: `progn', the simplest control construct of Lisp.
  49.  
  50.    A `progn' special form looks like this:
  51.  
  52.      (progn A B C ...)
  53.  
  54. and it says to execute the forms A, B, C and so on, in that order.
  55. These forms are called the body of the `progn' form.  The value of the
  56. last form in the body becomes the value of the entire `progn'.
  57.  
  58.    When Lisp was young, `progn' was the only way to execute two or more
  59. forms in succession and use the value of the last of them.  But
  60. programmers found they often needed to use a `progn' in the body of a
  61. function, where (at that time) only one form was allowed.  So the body
  62. of a function was made into an "implicit `progn'": several forms are
  63. allowed just as in the body of an actual `progn'.  Many other control
  64. structures likewise contain an implicit `progn'.  As a result, `progn'
  65. is not used as often as it used to be.  It is needed now most often
  66. inside of an `unwind-protect', `and', or `or'.
  67.  
  68.  - Special Form: progn FORMS...
  69.      This special form evaluates all of the FORMS, in textual order,
  70.      returning the result of the final form.
  71.  
  72.           (progn (print "The first form")
  73.                  (print "The second form")
  74.                  (print "The third form"))
  75.                -| "The first form"
  76.                -| "The second form"
  77.                -| "The third form"
  78.           => "The third form"
  79.  
  80.    Two other control constructs likewise evaluate a series of forms but
  81. return a different value:
  82.  
  83.  - Special Form: prog1 FORM1 FORMS...
  84.      This special form evaluates FORM1 and all of the FORMS, in textual
  85.      order, returning the result of FORM1.
  86.  
  87.           (prog1 (print "The first form")
  88.                  (print "The second form")
  89.                  (print "The third form"))
  90.                -| "The first form"
  91.                -| "The second form"
  92.                -| "The third form"
  93.           => "The first form"
  94.  
  95.      Here is a way to remove the first element from a list in the
  96.      variable `x', then return the value of that former element:
  97.  
  98.           (prog1 (car x) (setq x (cdr x)))
  99.  
  100.  - Special Form: prog2 FORM1 FORM2 FORMS...
  101.      This special form evaluates FORM1, FORM2, and all of the following
  102.      FORMS, in textual order, returning the result of FORM2.
  103.  
  104.           (prog2 (print "The first form")
  105.                  (print "The second form")
  106.                  (print "The third form"))
  107.                -| "The first form"
  108.                -| "The second form"
  109.                -| "The third form"
  110.           => "The second form"
  111.  
  112. 
  113. File: elisp,  Node: Conditionals,  Next: Combining Conditions,  Prev: Sequencing,  Up: Control Structures
  114.  
  115. Conditionals
  116. ============
  117.  
  118.    Conditional control structures choose among alternatives.  Emacs Lisp
  119. has two conditional forms: `if', which is much the same as in other
  120. languages, and `cond', which is a generalized case statement.
  121.  
  122.  - Special Form: if CONDITION THEN-FORM ELSE-FORMS...
  123.      `if' chooses between the THEN-FORM and the ELSE-FORMS based on the
  124.      value of CONDITION.  If the evaluated CONDITION is non-`nil',
  125.      THEN-FORM is evaluated and the result returned.  Otherwise, the
  126.      ELSE-FORMS are evaluated in textual order, and the value of the
  127.      last one is returned.  (The ELSE part of `if' is an example of an
  128.      implicit `progn'.  *Note Sequencing::.)
  129.  
  130.      If CONDITION has the value `nil', and no ELSE-FORMS are given,
  131.      `if' returns `nil'.
  132.  
  133.      `if' is a special form because the branch which is not selected is
  134.      never evaluated--it is ignored.  Thus, in the example below,
  135.      `true' is not printed because `print' is never called.
  136.  
  137.           (if nil
  138.               (print 'true)
  139.             'very-false)
  140.           => very-false
  141.  
  142.  - Special Form: cond CLAUSE...
  143.      `cond' chooses among an arbitrary number of alternatives.  Each
  144.      CLAUSE in the `cond' must be a list.  The CAR of this list is the
  145.      CONDITION; the remaining elements, if any, the BODY-FORMS.  Thus,
  146.      a clause looks like this:
  147.  
  148.           (CONDITION BODY-FORMS...)
  149.  
  150.      `cond' tries the clauses in textual order, by evaluating the
  151.      CONDITION of each clause.  If the value of CONDITION is non-`nil',
  152.      the BODY-FORMS are evaluated, and the value of the last of
  153.      BODY-FORMS becomes the value of the `cond'.  The remaining clauses
  154.      are ignored.
  155.  
  156.      If the value of CONDITION is `nil', the clause "fails", so the
  157.      `cond' moves on to the following clause, trying its CONDITION.
  158.  
  159.      If every CONDITION evaluates to `nil', so that every clause fails,
  160.      `cond' returns `nil'.
  161.  
  162.      A clause may also look like this:
  163.  
  164.           (CONDITION)
  165.  
  166.      Then, if CONDITION is non-`nil' when tested, the value of
  167.      CONDITION becomes the value of the `cond' form.
  168.  
  169.      The following example has four clauses, which test for the cases
  170.      where the value of `x' is a number, string, buffer and symbol,
  171.      respectively:
  172.  
  173.           (cond ((numberp x) x)
  174.                 ((stringp x) x)
  175.                 ((bufferp x)
  176.                  (setq temporary-hack x) ; multiple body-forms
  177.                  (buffer-name x))        ; in one clause
  178.                 ((symbolp x) (symbol-value x)))
  179.  
  180.      Often we want the last clause to be executed whenever none of the
  181.      previous clauses was successful.  To do this, we use `t' as the
  182.      CONDITION of the last clause, like this: `(t BODY-FORMS)'.  The
  183.      form `t' evaluates to `t', which is never `nil', so this clause
  184.      never fails, provided the `cond' gets to it at all.
  185.  
  186.      For example,
  187.  
  188.           (cond ((eq a 1) 'foo)
  189.                 (t "default"))
  190.           => "default"
  191.  
  192.      This expression is a `cond' which returns `foo' if the value of
  193.      `a' is 1, and returns the string `"default"' otherwise.
  194.  
  195.    Both `cond' and `if' can usually be written in terms of the other.
  196. Therefore, the choice between them is a matter of taste and style.  For
  197. example:
  198.  
  199.      (if A B C)
  200.      ==
  201.      (cond (A B) (t C))
  202.  
  203. 
  204. File: elisp,  Node: Combining Conditions,  Next: Iteration,  Prev: Conditionals,  Up: Control Structures
  205.  
  206. Constructs for Combining Conditions
  207. ===================================
  208.  
  209.    This section describes three constructs that are often used together
  210. with `if' and `cond' to express complicated conditions.  The constructs
  211. `and' and `or' can also be used individually as kinds of multiple
  212. conditional constructs.
  213.  
  214.  - Function: not CONDITION
  215.      This function tests for the falsehood of CONDITION.  It returns
  216.      `t' if CONDITION is `nil', and `nil' otherwise.  The function
  217.      `not' is identical to `null', and we recommend using `null' if you
  218.      are testing for an empty list.
  219.  
  220.  - Special Form: and CONDITIONS...
  221.      The `and' special form tests whether all the CONDITIONS are true.
  222.      It works by evaluating the CONDITIONS one by one in the order
  223.      written.
  224.  
  225.      If any of the CONDITIONS evaluates to `nil', then the result of
  226.      the `and' must be `nil' regardless of the remaining CONDITIONS; so
  227.      the remaining CONDITIONS are ignored and the `and' returns right
  228.      away.
  229.  
  230.      If all the CONDITIONS turn out non-`nil', then the value of the
  231.      last of them becomes the value of the `and' form.
  232.  
  233.      Here is an example.  The first condition returns the integer 1,
  234.      which is not `nil'.  Similarly, the second condition returns the
  235.      integer 2, which is not `nil'.  The third condition is `nil', so
  236.      the remaining condition is never evaluated.
  237.  
  238.           (and (print 1) (print 2) nil (print 3))
  239.                -| 1
  240.                -| 2
  241.           => nil
  242.  
  243.      Here is a more realistic example of using `and':
  244.  
  245.           (if (and (consp foo) (eq (car foo) 'x))
  246.               (message "foo is a list starting with x"))
  247.  
  248.      Note that `(car foo)' is not executed if `(consp foo)' returns
  249.      `nil', thus avoiding an error.
  250.  
  251.      `and' can be expressed in terms of either `if' or `cond'.  For
  252.      example:
  253.  
  254.           (and ARG1 ARG2 ARG3)
  255.           ==
  256.           (if ARG1 (if ARG2 ARG3))
  257.           ==
  258.           (cond (ARG1 (cond (ARG2 ARG3))))
  259.  
  260.  - Special Form: or CONDITIONS...
  261.      The `or' special form tests whether at least one of the CONDITIONS
  262.      is true.  It works by evaluating all the CONDITIONS one by one in
  263.      the order written.
  264.  
  265.      If any of the CONDITIONS evaluates to a non-`nil' value, then the
  266.      result of the `or' must be non-`nil'; so the remaining CONDITIONS
  267.      are ignored and the `or' returns right away.  The value it returns
  268.      is the non-`nil' value of the condition just evaluated.
  269.  
  270.      If all the CONDITIONS turn out `nil', then the `or' expression
  271.      returns `nil'.
  272.  
  273.      For example, this expression tests whether `x' is either 0 or
  274.      `nil':
  275.  
  276.           (or (eq x nil) (= x 0))
  277.  
  278.      Like the `and' construct, `or' can be written in terms of `cond'.
  279.      For example:
  280.  
  281.           (or ARG1 ARG2 ARG3)
  282.           ==
  283.           (cond (ARG1)
  284.                 (ARG2)
  285.                 (ARG3))
  286.  
  287.      You could almost write `or' in terms of `if', but not quite:
  288.  
  289.           (if ARG1 ARG1
  290.             (if ARG2 ARG2
  291.               ARG3))
  292.  
  293.      This is not completely equivalent because it can evaluate ARG1 or
  294.      ARG2 twice.  By contrast, `(or ARG1 ARG2 ARG3)' never evaluates
  295.      any argument more than once.
  296.  
  297. 
  298. File: elisp,  Node: Iteration,  Next: Nonlocal Exits,  Prev: Combining Conditions,  Up: Control Structures
  299.  
  300. Iteration
  301. =========
  302.  
  303.    Iteration means executing part of a program repetitively.  For
  304. example, you might want to repeat some expressions once for each
  305. element of a list, or once for each integer from 0 to N.  You can do
  306. this in Emacs Lisp with the special form `while':
  307.  
  308.  - Special Form: while CONDITION FORMS...
  309.      `while' first evaluates CONDITION.  If the result is non-`nil', it
  310.      evaluates FORMS in textual order.  Then it reevaluates CONDITION,
  311.      and if the result is non-`nil', it evaluates FORMS again.  This
  312.      process repeats until CONDITION evaluates to `nil'.
  313.  
  314.      There is no limit on the number of iterations that may occur.  The
  315.      loop will continue until either CONDITION evaluates to `nil' or
  316.      until an error or `throw' jumps out of it (*note Nonlocal
  317.      Exits::.).
  318.  
  319.      The value of a `while' form is always `nil'.
  320.  
  321.           (setq num 0)
  322.                => 0
  323.           (while (< num 4)
  324.             (princ (format "Iteration %d." num))
  325.             (setq num (1+ num)))
  326.                -| Iteration 0.
  327.                -| Iteration 1.
  328.                -| Iteration 2.
  329.                -| Iteration 3.
  330.                => nil
  331.  
  332.      If you would like to execute something on each iteration before the
  333.      end-test, put it together with the end-test in a `progn' as the
  334.      first argument of `while', as shown here:
  335.  
  336.           (while (progn
  337.                    (forward-line 1)
  338.                    (not (looking-at "^$"))))
  339.  
  340.      This moves forward one line and continues moving by lines until an
  341.      empty line is reached.
  342.  
  343. 
  344. File: elisp,  Node: Nonlocal Exits,  Prev: Iteration,  Up: Control Structures
  345.  
  346. Nonlocal Exits
  347. ==============
  348.  
  349.    A "nonlocal exit" is a transfer of control from one point in a
  350. program to another remote point.  Nonlocal exits can occur in Emacs Lisp
  351. as a result of errors; you can also use them under explicit control.
  352. Nonlocal exits unbind all variable bindings made by the constructs being
  353. exited.
  354.  
  355. * Menu:
  356.  
  357. * Catch and Throw::     Nonlocal exits for the program's own purposes.
  358. * Examples of Catch::   Showing how such nonlocal exits can be written.
  359. * Errors::              How errors are signaled and handled.
  360. * Cleanups::            Arranging to run a cleanup form if an error happens.
  361.  
  362. 
  363. File: elisp,  Node: Catch and Throw,  Next: Examples of Catch,  Up: Nonlocal Exits
  364.  
  365. Explicit Nonlocal Exits: `catch' and `throw'
  366. --------------------------------------------
  367.  
  368.    Most control constructs affect only the flow of control within the
  369. construct itself.  The function `throw' is the exception to this rule
  370. for of normal program execution: it performs a nonlocal exit on
  371. request.  (There are other exceptions, but they are for error handling
  372. only.)  `throw' is used inside a `catch', and jumps back to that
  373. `catch'.  For example:
  374.  
  375.      (catch 'foo
  376.        (progn
  377.          ...
  378.            (throw 'foo t)
  379.          ...))
  380.  
  381. The `throw' transfers control straight back to the corresponding
  382. `catch', which returns immediately.  The code following the `throw' is
  383. not executed.  The second argument of `throw' is used as the return
  384. value of the `catch'.
  385.  
  386.    The `throw' and the `catch' are matched through the first argument:
  387. `throw' searches for a `catch' whose first argument is `eq' to the one
  388. specified.  Thus, in the above example, the `throw' specifies `foo',
  389. and the `catch' specifies the same symbol, so that `catch' is
  390. applicable.  If there is more than one applicable `catch', the
  391. innermost one takes precedence.
  392.  
  393.    All Lisp constructs between the `catch' and the `throw', including
  394. function calls, are exited automatically along with the `catch'.  When
  395. binding constructs such as `let' or function calls are exited in this
  396. way, the bindings are unbound, just as they are when these constructs
  397. are exited normally (*note Local Variables::.).  Likewise, the buffer
  398. and position saved by `save-excursion' (*note Excursions::.) are
  399. restored, and so is the narrowing status saved by `save-restriction'
  400. and the window selection saved by `save-window-excursion' (*note Window
  401. Configurations::.).  Any cleanups established with the `unwind-protect'
  402. special form are executed if the `unwind-protect' is exited with a
  403. `throw'.
  404.  
  405.    The `throw' need not appear lexically within the `catch' that it
  406. jumps to.  It can equally well be called from another function called
  407. within the `catch'.  As long as the `throw' takes place chronologically
  408. after entry to the `catch', and chronologically before exit from it, it
  409. has access to that `catch'.  This is why `throw' can be used in
  410. commands such as `exit-recursive-edit' which throw back to the editor
  411. command loop (*note Recursive Editing::.).
  412.  
  413.      Common Lisp note: most other versions of Lisp, including Common
  414.      Lisp, have several ways of transferring control nonsequentially:
  415.      `return', `return-from', and `go', for example.  Emacs Lisp has
  416.      only `throw'.
  417.  
  418.  - Special Form: catch TAG BODY...
  419.      `catch' establishes a return point for the `throw' function.  The
  420.      return point is distinguished from other such return points by TAG,
  421.      which may be any Lisp object.  The argument TAG is evaluated
  422.      normally before the return point is established.
  423.  
  424.      With the return point in effect, the forms of the BODY are
  425.      evaluated in textual order.  If the forms execute normally,
  426.      without error or nonlocal exit, the value of the last body form is
  427.      returned from the `catch'.
  428.  
  429.      If a `throw' is done within BODY specifying the same value TAG,
  430.      the `catch' exits immediately; the value it returns is whatever
  431.      was specified as the second argument of `throw'.
  432.  
  433.  - Function: throw TAG VALUE
  434.      The purpose of `throw' is to return from a return point previously
  435.      established with `catch'.  The argument TAG is used to choose
  436.      among the various existing return points; it must be `eq' to the
  437.      value specified in the `catch'.  If multiple return points match
  438.      TAG, the innermost one is used.
  439.  
  440.      The argument VALUE is used as the value to return from that
  441.      `catch'.
  442.  
  443.      If no return point is in effect with tag TAG, then a `no-catch'
  444.      error is signaled with data `(TAG VALUE)'.
  445.  
  446. 
  447. File: elisp,  Node: Examples of Catch,  Next: Errors,  Prev: Catch and Throw,  Up: Nonlocal Exits
  448.  
  449. Examples of `catch' and `throw'
  450. -------------------------------
  451.  
  452.    One way to use `catch' and `throw' is to exit from a doubly nested
  453. loop.  (In most languages, this would be done with a "go to".) Here we
  454. compute `(foo I J)' for I and J varying from 0 to 9:
  455.  
  456.      (defun search-foo ()
  457.        (catch 'loop
  458.          (let ((i 0))
  459.            (while (< i 10)
  460.              (let ((j 0))
  461.                (while (< j 10)
  462.                  (if (foo i j)
  463.                      (throw 'loop (list i j)))
  464.                  (setq j (1+ j))))
  465.              (setq i (1+ i))))))
  466.  
  467. If `foo' ever returns non-`nil', we stop immediately and return a list
  468. of I and J.  If `foo' always returns `nil', the `catch' returns
  469. normally, and the value is `nil', since that is the result of the
  470. `while'.
  471.  
  472.    Here are two tricky examples, slightly different, showing two return
  473. points at once.  First, two return points with the same tag, `hack':
  474.  
  475.      (defun catch2 (tag)
  476.        (catch tag
  477.          (throw 'hack 'yes)))
  478.      => catch2
  479.      
  480.      (catch 'hack
  481.        (print (catch2 'hack))
  482.        'no)
  483.      -| yes
  484.      => no
  485.  
  486. Since both return points have tags that match the `throw', it goes to
  487. the inner one, the one established in `catch2'.  Therefore, `catch2'
  488. returns normally with value `yes', and this value is printed.  Finally
  489. the second body form in the outer `catch', which is `'no', is evaluated
  490. and returned from the outer `catch'.
  491.  
  492.    Now let's change the argument given to `catch2':
  493.  
  494.      (defun catch2 (tag)
  495.        (catch tag
  496.          (throw 'hack 'yes)))
  497.      => catch2
  498.      
  499.      (catch 'hack
  500.        (print (catch2 'quux))
  501.        'no)
  502.      => yes
  503.  
  504. We still have two return points, but this time only the outer one has
  505. the tag `hack'; the inner one has the tag `quux' instead.  Therefore,
  506. the `throw' returns the value `yes' from the outer return point.  The
  507. function `print' is never called, and the body-form `'no' is never
  508. evaluated.
  509.  
  510. 
  511. File: elisp,  Node: Errors,  Next: Cleanups,  Prev: Examples of Catch,  Up: Nonlocal Exits
  512.  
  513. Errors
  514. ------
  515.  
  516.    When Emacs Lisp attempts to evaluate a form that, for some reason,
  517. cannot be evaluated, it "signals" an "error".
  518.  
  519.    When an error is signaled, Emacs's default reaction is to print an
  520. error message and terminate execution of the current command.  This is
  521. the right thing to do in most cases, such as if you type `C-f' at the
  522. end of the buffer.
  523.  
  524.    In complicated programs, simple termination may not be what you want.
  525. For example, the program may have made temporary changes in data
  526. structures, or created temporary buffers which should be deleted before
  527. the program is finished.  In such cases, you would use `unwind-protect'
  528. to establish "cleanup expressions" to be evaluated in case of error.
  529. Occasionally, you may wish the program to continue execution despite an
  530. error in a subroutine.  In these cases, you would use `condition-case'
  531. to establish "error handlers" to recover control in case of error.
  532.  
  533.    Resist the temptation to use error handling to transfer control from
  534. one part of the program to another; use `catch' and `throw'.  *Note
  535. Catch and Throw::.
  536.  
  537. * Menu:
  538.  
  539. * Signaling Errors::      How to report an error.
  540. * Processing of Errors::  What Emacs does when you report an error.
  541. * Handling Errors::       How you can trap errors and continue execution.
  542. * Error Names::           How errors are classified for trapping them.
  543.  
  544. 
  545. File: elisp,  Node: Signaling Errors,  Next: Processing of Errors,  Up: Errors
  546.  
  547. How to Signal an Error
  548. ......................
  549.  
  550.    Most errors are signaled "automatically" within Lisp primitives
  551. which you call for other purposes, such as if you try to take the CAR
  552. of an integer or move forward a character at the end of the buffer; you
  553. can also signal errors explicitly with the functions `error' and
  554. `signal'.
  555.  
  556.    Quitting, which happens when the user types `C-g', is not considered
  557. an error, but it handled almost like an error.  *Note Quitting::.
  558.  
  559.  - Function: error FORMAT-STRING &rest ARGS
  560.      This function signals an error with an error message constructed by
  561.      applying `format' (*note String Conversion::.) to FORMAT-STRING
  562.      and ARGS.
  563.  
  564.      Typical uses of `error' is shown in the following examples:
  565.  
  566.           (error "You have committed an error.
  567.                   Try something else.")
  568.                error--> You have committed an error.
  569.                   Try something else.
  570.           
  571.           (error "You have committed %d errors." 10)
  572.                error--> You have committed 10 errors.
  573.  
  574.      `error' works by calling `signal' with two arguments: the error
  575.      symbol `error', and a list containing the string returned by
  576.      `format'.
  577.  
  578.      If you want to use a user-supplied string as an error message
  579.      verbatim, don't just write `(error STRING)'.  If STRING contains
  580.      `%', it will be interpreted as a format specifier, with undesirable
  581.      results.  Instead, use `(error "%s" STRING)'.
  582.  
  583.  - Function: signal ERROR-SYMBOL DATA
  584.      This function signals an error named by ERROR-SYMBOL.  The
  585.      argument DATA is a list of additional Lisp objects relevant to the
  586.      circumstances of the error.
  587.  
  588.      The argument ERROR-SYMBOL must be an "error symbol"--a symbol
  589.      bearing a property `error-conditions' whose value is a list of
  590.      condition names.  This is how different sorts of errors are
  591.      classified.
  592.  
  593.      The number and significance of the objects in DATA depends on
  594.      ERROR-SYMBOL.  For example, with a `wrong-type-arg' error, there
  595.      are two objects in the list: a predicate which describes the type
  596.      that was expected, and the object which failed to fit that type.
  597.      *Note Error Names::, for a description of error symbols.
  598.  
  599.      Both ERROR-SYMBOL and DATA are available to any error handlers
  600.      which handle the error: a list `(ERROR-SYMBOL . DATA)' is
  601.      constructed to become the value of the local variable bound in the
  602.      `condition-case' form (*note Handling Errors::.).  If the error is
  603.      not handled, both of them are used in printing the error message.
  604.  
  605.      The function `signal' never returns (though in older Emacs versions
  606.      it could sometimes return).
  607.  
  608.           (signal 'wrong-number-of-arguments '(x y))
  609.                error--> Wrong number of arguments: x, y
  610.  
  611.           (signal 'no-such-error '("My unknown error condition."))
  612.                error--> peculiar error: "My unknown error condition."
  613.  
  614.      Common Lisp note: Emacs Lisp has nothing like the Common Lisp
  615.      concept of continuable errors.
  616.  
  617. 
  618. File: elisp,  Node: Processing of Errors,  Next: Handling Errors,  Prev: Signaling Errors,  Up: Errors
  619.  
  620. How Emacs Processes Errors
  621. ..........................
  622.  
  623.    When an error is signaled, Emacs searches for an active "handler"
  624. for the error.  A handler is a specially marked place in the Lisp code
  625. of the current function or any of the functions by which it was called.
  626. If an applicable handler exists, its code is executed, and control
  627. resumes following the handler.  The handler executes in the environment
  628. of the `condition-case' which established it; all functions called
  629. within that `condition-case' have already been exited, and the handler
  630. cannot return to them.
  631.  
  632.    If no applicable handler is in effect in your program, the current
  633. command is terminated and control returns to the editor command loop,
  634. because the command loop has an implicit handler for all kinds of
  635. errors.  The command loop's handler uses the error symbol and associated
  636. data to print an error message.
  637.  
  638.    When an error is not handled explicitly, it may cause the Lisp
  639. debugger to be called.  The debugger is enabled if the variable
  640. `debug-on-error' (*note Error Debugging::.) is non-`nil'.  Unlike error
  641. handlers, the debugger runs in the environment of the error, so that
  642. you can examine values of variables precisely as they were at the time
  643. of the error.
  644.  
  645. 
  646. File: elisp,  Node: Handling Errors,  Next: Error Names,  Prev: Processing of Errors,  Up: Errors
  647.  
  648. Writing Code to Handle Errors
  649. .............................
  650.  
  651.    The usual effect of signaling an error is to terminate the command
  652. that is running and return immediately to the Emacs editor command loop.
  653. You can arrange to trap errors occurring in a part of your program by
  654. establishing an "error handler" with the special form `condition-case'.
  655. A simple example looks like this:
  656.  
  657.      (condition-case nil
  658.          (delete-file filename)
  659.        (error nil))
  660.  
  661. This deletes the file named FILENAME, catching any error and returning
  662. `nil' if an error occurs.
  663.  
  664.    The second argument of `condition-case' is called the "protected
  665. form".  (In the example above, the protected form is a call to
  666. `delete-file'.)  The error handlers go into effect when this form
  667. begins execution and are deactivated when this form returns.  They
  668. remain in effect for all the intervening time.  In particular, they are
  669. in effect during the execution of subroutines called by this form, and
  670. their subroutines, and so on.  This is a good thing, since, strictly
  671. speaking, errors can be signaled only by Lisp primitives (including
  672. `signal' and `error') called by the protected form, not by the
  673. protected form itself.
  674.  
  675.    The arguments after the protected form are handlers.  Each handler
  676. lists one or more "condition names" (which are symbols) to specify
  677. which errors it will handle.  The error symbol specified when an error
  678. is signaled also defines a list of condition names.  A handler applies
  679. to an error if they have any condition names in common.  In the example
  680. above, there is one handler, and it specifies one condition name,
  681. `error', which covers all errors.
  682.  
  683.    The search for an applicable handler checks all the established
  684. handlers starting with the most recently established one.  Thus, if two
  685. nested `condition-case' forms try to handle the same error, the inner of
  686. the two will actually handle it.
  687.  
  688.    When an error is handled, control returns to the handler.  Before
  689. this happens, Emacs unbinds all variable bindings made by binding
  690. constructs that are being exited and executes the cleanups of all
  691. `unwind-protect' forms that are exited.  Once control arrives at the
  692. handler, the body of the handler is executed.
  693.  
  694.    After execution of the handler body, execution continues by returning
  695. from the `condition-case' form.  Because the protected form is exited
  696. completely before execution of the handler, the handler cannot resume
  697. execution at the point of the error, nor can it examine variable
  698. bindings that were made within the protected form.  All it can do is
  699. clean up and proceed.
  700.  
  701.    `condition-case' is often used to trap errors that are predictable,
  702. such as failure to open a file in a call to `insert-file-contents'.  It
  703. is also used to trap errors that are totally unpredictable, such as
  704. when the program evaluates an expression read from the user.
  705.  
  706.    Error signaling and handling have some resemblance to `throw' and
  707. `catch', but they are entirely separate facilities.  An error cannot be
  708. caught by a `catch', and a `throw' cannot be handled by an error
  709. handler (though using `throw' when there is no suitable `catch' signals
  710. an error which can be handled).
  711.  
  712.  - Special Form: condition-case VAR PROTECTED-FORM HANDLERS...
  713.      This special form establishes the error handlers HANDLERS around
  714.      the execution of PROTECTED-FORM.  If PROTECTED-FORM executes
  715.      without error, the value it returns becomes the value of the
  716.      `condition-case' form; in this case, the `condition-case' has no
  717.      effect.  The `condition-case' form makes a difference when an
  718.      error occurs during PROTECTED-FORM.
  719.  
  720.      Each of the HANDLERS is a list of the form `(CONDITIONS BODY...)'.
  721.      CONDITIONS is an error condition name to be handled, or a list of
  722.      condition names; BODY is one or more Lisp expressions to be
  723.      executed when this handler handles an error.  Here are examples of
  724.      handlers:
  725.  
  726.           (error nil)
  727.           
  728.           (arith-error (message "Division by zero"))
  729.           
  730.           ((arith-error file-error)
  731.            (message
  732.             "Either division by zero or failure to open a file"))
  733.  
  734.      Each error that occurs has an "error symbol" which describes what
  735.      kind of error it is.  The `error-conditions' property of this
  736.      symbol is a list of condition names (*note Error Names::.).  Emacs
  737.      searches all the active `condition-case' forms for a handler which
  738.      specifies one or more of these names; the innermost matching
  739.      `condition-case' handles the error.  The handlers in this
  740.      `condition-case' are tested in the order in which they appear.
  741.  
  742.      The body of the handler is then executed, and the `condition-case'
  743.      returns normally, using the value of the last form in the body as
  744.      the overall value.
  745.  
  746.      The argument VAR is a variable.  `condition-case' does not bind
  747.      this variable when executing the PROTECTED-FORM, only when it
  748.      handles an error.  At that time, VAR is bound locally to a list of
  749.      the form `(ERROR-SYMBOL . DATA)', giving the particulars of the
  750.      error.  The handler can refer to this list to decide what to do.
  751.      For example, if the error is for failure opening a file, the file
  752.      name is the second element of DATA--the third element of VAR.
  753.  
  754.      If VAR is `nil', that means no variable is bound.  Then the error
  755.      symbol and associated data are not made available to the handler.
  756.  
  757.    Here is an example of using `condition-case' to handle the error
  758. that results from dividing by zero.  The handler prints out a warning
  759. message and returns a very large number.
  760.  
  761.      (defun safe-divide (dividend divisor)
  762.        (condition-case err
  763.            ;; Protected form.
  764.            (/ dividend divisor)
  765.          ;; The handler.
  766.          (arith-error                        ; Condition.
  767.           (princ (format "Arithmetic error: %s" err))
  768.           1000000)))
  769.      => safe-divide
  770.  
  771.      (safe-divide 5 0)
  772.           -| Arithmetic error: (arith-error)
  773.      => 1000000
  774.  
  775. The handler specifies condition name `arith-error' so that it will
  776. handle only division-by-zero errors.  Other kinds of errors will not be
  777. handled, at least not by this `condition-case'.  Thus,
  778.  
  779.      (safe-divide nil 3)
  780.           error--> Wrong type argument: integer-or-marker-p, nil
  781.  
  782.    Here is a `condition-case' that catches all kinds of errors,
  783. including those signaled with `error':
  784.  
  785.      (setq baz 34)
  786.           => 34
  787.  
  788.      (condition-case err
  789.          (if (eq baz 35)
  790.              t
  791.            ;; This is a call to the function `error'.
  792.            (error "Rats!  The variable %s was %s, not 35." 'baz baz))
  793.        ;; This is the handler; it is not a form.
  794.        (error (princ (format "The error was: %s" err))
  795.               2))
  796.      -| The error was: (error "Rats!  The variable baz was 34, not 35.")
  797.      => 2
  798.  
  799. 
  800. File: elisp,  Node: Error Names,  Prev: Handling Errors,  Up: Errors
  801.  
  802. Error Symbols and Condition Names
  803. .................................
  804.  
  805.    When you signal an error, you specify an "error symbol" to specify
  806. the kind of error you have in mind.  Each error has one and only one
  807. error symbol to categorize it.  This is the finest classification of
  808. errors defined by the Lisp language.
  809.  
  810.    These narrow classifications are grouped into a hierarchy of wider
  811. classes called "error conditions", identified by "condition names".
  812. The narrowest such classes belong to the error symbols themselves: each
  813. error symbol is also a condition name.  There are also condition names
  814. for more extensive classes, up to the condition name `error' which
  815. takes in all kinds of errors.  Thus, each error has one or more
  816. condition names: `error', the error symbol if that is distinct from
  817. `error', and perhaps some intermediate classifications.
  818.  
  819.    In order for a symbol to be usable as an error symbol, it must have
  820. an `error-conditions' property which gives a list of condition names.
  821. This list defines the conditions which this kind of error belongs to.
  822. (The error symbol itself, and the symbol `error', should always be
  823. members of this list.)  Thus, the hierarchy of condition names is
  824. defined by the `error-conditions' properties of the error symbols.
  825.  
  826.    In addition to the `error-conditions' list, the error symbol should
  827. have an `error-message' property whose value is a string to be printed
  828. when that error is signaled but not handled.  If the `error-message'
  829. property exists, but is not a string, the error message `peculiar
  830. error' is used.
  831.  
  832.    Here is how we define a new error symbol, `new-error':
  833.  
  834.      (put 'new-error
  835.           'error-conditions
  836.           '(error my-own-errors new-error))
  837.           => (error my-own-errors new-error)
  838.      (put 'new-error 'error-message "A new error")
  839.           => "A new error"
  840.  
  841. This error has three condition names: `new-error', the narrowest
  842. classification; `my-own-errors', which we imagine is a wider
  843. classification; and `error', which is the widest of all.
  844.  
  845.    Naturally, Emacs will never signal a `new-error' on its own; only an
  846. explicit call to `signal' (*note Errors::.) in your code can do this:
  847.  
  848.      (signal 'new-error '(x y))
  849.           error--> A new error: x, y
  850.  
  851.    This error can be handled through any of the three condition names.
  852. This example handles `new-error' and any other errors in the class
  853. `my-own-errors':
  854.  
  855.      (condition-case foo
  856.          (bar nil t)
  857.        (my-own-errors nil))
  858.  
  859.    The significant way that errors are classified is by their condition
  860. names--the names used to match errors with handlers.  An error symbol
  861. serves only as a convenient way to specify the intended error message
  862. and list of condition names.  If `signal' were given a list of
  863. condition names rather than one error symbol, that would be cumbersome.
  864.  
  865.    By contrast, using only error symbols without condition names would
  866. seriously decrease the power of `condition-case'.  Condition names make
  867. it possible to categorize errors at various levels of generality when
  868. you write an error handler.  Using error symbols alone would eliminate
  869. all but the narrowest level of classification.
  870.  
  871.    *Note Standard Errors::, for a list of all the standard error symbols
  872. and their conditions.
  873.  
  874. 
  875. File: elisp,  Node: Cleanups,  Prev: Errors,  Up: Nonlocal Exits
  876.  
  877. Cleaning Up from Nonlocal Exits
  878. -------------------------------
  879.  
  880.    The `unwind-protect' construct is essential whenever you temporarily
  881. put a data structure in an inconsistent state; it permits you to ensure
  882. the data are consistent in the event of an error or throw.
  883.  
  884.  - Special Form: unwind-protect BODY CLEANUP-FORMS...
  885.      `unwind-protect' executes the BODY with a guarantee that the
  886.      CLEANUP-FORMS will be evaluated if control leaves BODY, no matter
  887.      how that happens.  The BODY may complete normally, or execute a
  888.      `throw' out of the `unwind-protect', or cause an error; in all
  889.      cases, the CLEANUP-FORMS will be evaluated.
  890.  
  891.      Only the BODY is actually protected by the `unwind-protect'.  If
  892.      any of the CLEANUP-FORMS themselves exit nonlocally (e.g., via a
  893.      `throw' or an error), it is *not* guaranteed that the rest of them
  894.      will be executed.  If the failure of one of the CLEANUP-FORMS has
  895.      the potential to cause trouble, then it should be protected by
  896.      another `unwind-protect' around that form.
  897.  
  898.      The number of currently active `unwind-protect' forms counts,
  899.      together with the number of local variable bindings, against the
  900.      limit `max-specpdl-size' (*note Local Variables::.).
  901.  
  902.    For example, here we make an invisible buffer for temporary use, and
  903. make sure to kill it before finishing:
  904.  
  905.      (save-excursion
  906.        (let ((buffer (get-buffer-create " *temp*")))
  907.          (set-buffer buffer)
  908.          (unwind-protect
  909.              BODY
  910.            (kill-buffer buffer))))
  911.  
  912. You might think that we could just as well write `(kill-buffer
  913. (current-buffer))' and dispense with the variable `buffer'.  However,
  914. the way shown above is safer, if BODY happens to get an error after
  915. switching to a different buffer!  (Alternatively, you could write
  916. another `save-excursion' around the body, to ensure that the temporary
  917. buffer becomes current in time to kill it.)
  918.  
  919.    Here is an actual example taken from the file `ftp.el'.  It creates
  920. a process (*note Processes::.) to try to establish a connection to a
  921. remote machine.  As the function `ftp-login' is highly susceptible to
  922. numerous problems which the writer of the function cannot anticipate,
  923. it is protected with a form that guarantees deletion of the process in
  924. the event of failure.  Otherwise, Emacs might fill up with useless
  925. subprocesses.
  926.  
  927.      (let ((win nil))
  928.        (unwind-protect
  929.            (progn
  930.              (setq process (ftp-setup-buffer host file))
  931.              (if (setq win (ftp-login process host user password))
  932.                  (message "Logged in")
  933.                (error "Ftp login failed")))
  934.          (or win (and process (delete-process process)))))
  935.  
  936.    This example actually has a small bug: if the user types `C-g' to
  937. quit, and the quit happens immediately after the function
  938. `ftp-setup-buffer' returns but before the variable `process' is set,
  939. the process will not be killed.  There is no easy way to fix this bug,
  940. but at least it is very unlikely.
  941.  
  942. 
  943. File: elisp,  Node: Variables,  Next: Functions,  Prev: Control Structures,  Up: Top
  944.  
  945. Variables
  946. *********
  947.  
  948.    A "variable" is a name used in a program to stand for a value.
  949. Nearly all programming languages have variables of some sort.  In the
  950. text for a Lisp program, variables are written using the syntax for
  951. symbols.
  952.  
  953.    In Lisp, unlike most programming languages, programs are represented
  954. primarily as Lisp objects and only secondarily as text.  The Lisp
  955. objects used for variables are symbols: the symbol name is the variable
  956. name, and the variable's value is stored in the value cell of the
  957. symbol.  The use of a symbol as a variable is independent of whether
  958. the same symbol has a function definition.  *Note Symbol Components::.
  959.  
  960.    The textual form of a program is determined by its Lisp object
  961. representation; it is the read syntax for the Lisp object which
  962. constitutes the program.  This is why a variable in a textual Lisp
  963. program is written as the read syntax for the symbol that represents the
  964. variable.
  965.  
  966. * Menu:
  967.  
  968. * Global Variables::      Variable values that exist permanently, everywhere.
  969. * Constant Variables::    Certain "variables" have values that never change.
  970. * Local Variables::       Variable values that exist only temporarily.
  971. * Void Variables::        Symbols that lack values.
  972. * Defining Variables::    A definition says a symbol is used as a variable.
  973. * Accessing Variables::   Examining values of variables whose names
  974.                             are known only at run time.
  975. * Setting Variables::     Storing new values in variables.
  976. * Variable Scoping::      How Lisp chooses among local and global values.
  977. * Buffer-Local Variables::  Variable values in effect only in one buffer.
  978.  
  979. 
  980. File: elisp,  Node: Global Variables,  Next: Constant Variables,  Prev: Variables,  Up: Variables
  981.  
  982. Global Variables
  983. ================
  984.  
  985.    The simplest way to use a variable is "globally".  This means that
  986. the variable has just one value at a time, and this value is in effect
  987. (at least for the moment) throughout the Lisp system.  The value remains
  988. in effect until you specify a new one.  When a new value replaces the
  989. old one, no trace of the old value remains in the variable.
  990.  
  991.    You specify a value for a symbol with `setq'.  For example,
  992.  
  993.      (setq x '(a b))
  994.  
  995. gives the variable `x' the value `(a b)'.  Note that the first argument
  996. of `setq', the name of the variable, is not evaluated, but the second
  997. argument, the desired value, is evaluated normally.
  998.  
  999.    Once the variable has a value, you can refer to it by using the
  1000. symbol by itself as an expression.  Thus,
  1001.  
  1002.      x
  1003.           => (a b)
  1004.  
  1005. assuming the `setq' form shown above has already been executed.
  1006.  
  1007.    If you do another `setq', the new value replaces the old one:
  1008.  
  1009.      x
  1010.           => (a b)
  1011.      (setq x 4)
  1012.           => 4
  1013.      x
  1014.           => 4
  1015.  
  1016. 
  1017. File: elisp,  Node: Constant Variables,  Next: Local Variables,  Prev: Global Variables,  Up: Variables
  1018.  
  1019. Variables that Never Change
  1020. ===========================
  1021.  
  1022.    Emacs Lisp has two special symbols, `nil' and `t', that always
  1023. evaluate to themselves.  These symbols cannot be rebound, nor can their
  1024. value cells be changed.  An attempt to change the value of `nil' or `t'
  1025. signals a `setting-constant' error.
  1026.  
  1027.      nil == 'nil
  1028.           => nil
  1029.      (setq nil 500)
  1030.      error--> Attempt to set constant symbol: nil
  1031.  
  1032. 
  1033. File: elisp,  Node: Local Variables,  Next: Void Variables,  Prev: Constant Variables,  Up: Variables
  1034.  
  1035. Local Variables
  1036. ===============
  1037.  
  1038.    Global variables are given values that last until explicitly
  1039. superseded with new values.  Sometimes it is useful to create variable
  1040. values that exist temporarily--only while within a certain part of the
  1041. program.  These values are called "local", and the variables so used
  1042. are called "local variables".
  1043.  
  1044.    For example, when a function is called, its argument variables
  1045. receive new local values which last until the function exits.
  1046. Similarly, the `let' special form explicitly establishes new local
  1047. values for specified variables; these last until exit from the `let'
  1048. form.
  1049.  
  1050.    When a local value is established, the previous value (or lack of
  1051. one) of the variable is saved away.  When the life span of the local
  1052. value is over, the previous value is restored.  In the mean time, we
  1053. say that the previous value is "shadowed" and "not visible".  Both
  1054. global and local values may be shadowed (*note Scope::.).
  1055.  
  1056.    If you set a variable (such as with `setq') while it is local, this
  1057. replaces the local value; it does not alter the global value, or
  1058. previous local values that are shadowed.  To model this behavior, we
  1059. speak of a "local binding" of the variable as well as a local value.
  1060.  
  1061.    The local binding is a conceptual place that holds a local value.
  1062. Entry to a function, or a special form such as `let', creates the local
  1063. binding; exit from the function or from the `let' removes the local
  1064. binding.  As long as the local binding lasts, the variable's value is
  1065. stored within it.  Use of `setq' or `set' while there is a local
  1066. binding stores a different value into the local binding; it does not
  1067. create a new binding.
  1068.  
  1069.    We also speak of the "global binding", which is where (conceptually)
  1070. the global value is kept.
  1071.  
  1072.    A variable can have more than one local binding at a time (for
  1073. example, if there are nested `let' forms that bind it).  In such a
  1074. case, the most recently created local binding that still exists is the
  1075. "current binding" of the variable.  (This is called "dynamic scoping";
  1076. see *Note Variable Scoping::.)  If there are no local bindings, the
  1077. variable's global binding is its current binding.  We also call the
  1078. current binding the "most-local existing binding", for emphasis.
  1079. Ordinary evaluation of a symbol always returns the value of its current
  1080. binding.
  1081.  
  1082.    The special forms `let' and `let*' exist to create local bindings.
  1083.  
  1084.  - Special Form: let (BINDINGS...) FORMS...
  1085.      This function binds variables according to BINDINGS and then
  1086.      evaluates all of the FORMS in textual order.  The `let'-form
  1087.      returns the value of the last form in FORMS.
  1088.  
  1089.      Each of the BINDINGS is either (i) a symbol, in which case that
  1090.      symbol is bound to `nil'; or (ii) a list of the form `(SYMBOL
  1091.      VALUE-FORM)', in which case SYMBOL is bound to the result of
  1092.      evaluating VALUE-FORM.  If VALUE-FORM is omitted, `nil' is used.
  1093.  
  1094.      All of the VALUE-FORMs in BINDINGS are evaluated in the order they
  1095.      appear and *before* any of the symbols are bound.  Here is an
  1096.      example of this: `Z' is bound to the old value of `Y', which is 2,
  1097.      not the new value, 1.
  1098.  
  1099.           (setq Y 2)
  1100.                => 2
  1101.           (let ((Y 1)
  1102.                 (Z Y))
  1103.             (list Y Z))
  1104.                => (1 2)
  1105.  
  1106.  - Special Form: let* (BINDINGS...) FORMS...
  1107.      This special form is like `let', except that each symbol in
  1108.      BINDINGS is bound as soon as its new value is computed, before the
  1109.      computation of the values of the following local bindings.
  1110.      Therefore, an expression in BINDINGS may reasonably refer to the
  1111.      preceding symbols bound in this `let*' form.  Compare the
  1112.      following example with the example above for `let'.
  1113.  
  1114.           (setq Y 2)
  1115.                => 2
  1116.           (let* ((Y 1)
  1117.                  (Z Y))    ; Use the just-established value of `Y'.
  1118.             (list Y Z))
  1119.                => (1 1)
  1120.  
  1121.    Here is a complete list of the other facilities which create local
  1122. bindings:
  1123.  
  1124.    * Function calls (*note Functions::.).
  1125.  
  1126.    * Macro calls (*note Macros::.).
  1127.  
  1128.    * `condition-case' (*note Errors::.).
  1129.  
  1130.  - Variable: max-specpdl-size
  1131.      This variable defines the limit on the total number of local
  1132.      variable bindings and `unwind-protect' cleanups (*note Nonlocal
  1133.      Exits::.) that are allowed before signaling an error (with data
  1134.      `"Variable binding depth exceeds max-specpdl-size"').
  1135.  
  1136.      This limit, with the associated error when it is exceeded, is one
  1137.      way that Lisp avoids infinite recursion on an ill-defined function.
  1138.  
  1139.      The default value is 600.
  1140.  
  1141.      `max-lisp-eval-depth' provides another limit on depth of nesting.
  1142.      *Note Eval::.
  1143.  
  1144. 
  1145. File: elisp,  Node: Void Variables,  Next: Defining Variables,  Prev: Local Variables,  Up: Variables
  1146.  
  1147. When a Variable is "Void"
  1148. =========================
  1149.  
  1150.    If you have never given a symbol any value as a global variable, we
  1151. say that that symbol's global value is "void".  In other words, the
  1152. symbol's value cell does not have any Lisp object in it.  If you try to
  1153. evaluate the symbol, you get a `void-variable' error rather than a
  1154. value.
  1155.  
  1156.    Note that a value of `nil' is not the same as void.  The symbol
  1157. `nil' is a Lisp object and can be the value of a variable just as any
  1158. other object can be; but it is *a value*.  A void variable does not
  1159. have any value.
  1160.  
  1161.    After you have given a variable a value, you can make it void once
  1162. more using `makunbound'.
  1163.  
  1164.  - Function: makunbound SYMBOL
  1165.      This function makes the current binding of SYMBOL void.  This
  1166.      causes any future attempt to use this symbol as a variable to
  1167.      signal the error `void-variable', unless or until you set it again.
  1168.  
  1169.      `makunbound' returns SYMBOL.
  1170.  
  1171.           (makunbound 'x)      ; Make the global value
  1172.                                ;   of `x' void.
  1173.                => x
  1174.           x
  1175.           error--> Symbol's value as variable is void: x
  1176.  
  1177.      If SYMBOL is locally bound, `makunbound' affects the most local
  1178.      existing binding.  This is the only way a symbol can have a void
  1179.      local binding, since all the constructs that create local bindings
  1180.      create them with values.  In this case, the voidness lasts at most
  1181.      as long as the binding does; when the binding is removed due to
  1182.      exit from the construct that made it, the previous or global
  1183.      binding is reexposed as usual, and the variable is no longer void
  1184.      unless the newly reexposed binding was void all along.
  1185.  
  1186.           (setq x 1)               ; Put a value in the global binding.
  1187.                => 1
  1188.           (let ((x 2))             ; Locally bind it.
  1189.             (makunbound 'x)        ; Void the local binding.
  1190.             x)
  1191.           error--> Symbol's value as variable is void: x
  1192.  
  1193.           x                        ; The global binding is unchanged.
  1194.                => 1
  1195.           
  1196.           (let ((x 2))             ; Locally bind it.
  1197.             (let ((x 3))           ; And again.
  1198.               (makunbound 'x)      ; Void the innermost-local binding.
  1199.               x))                  ; And refer: it's void.
  1200.           error--> Symbol's value as variable is void: x
  1201.  
  1202.           (let ((x 2))
  1203.             (let ((x 3))
  1204.               (makunbound 'x))     ; Void inner binding, then remove it.
  1205.             x)                     ; Now outer `let' binding is visible.
  1206.                => 2
  1207.  
  1208.    A variable that has been made void with `makunbound' is
  1209. indistinguishable from one that has never received a value and has
  1210. always been void.
  1211.  
  1212.    You can use the function `boundp' to test whether a variable is
  1213. currently void.
  1214.  
  1215.  - Function: boundp VARIABLE
  1216.      `boundp' returns `t' if VARIABLE (a symbol) is not void; more
  1217.      precisely, if its current binding is not void.  It returns `nil'
  1218.      otherwise.
  1219.  
  1220.           (boundp 'abracadabra)          ; Starts out void.
  1221.                => nil
  1222.  
  1223.           (let ((abracadabra 5))         ; Locally bind it.
  1224.             (boundp 'abracadabra))
  1225.                => t
  1226.  
  1227.           (boundp 'abracadabra)          ; Still globally void.
  1228.                => nil
  1229.  
  1230.           (setq abracadabra 5)           ; Make it globally nonvoid.
  1231.                => 5
  1232.  
  1233.           (boundp 'abracadabra)
  1234.                => t
  1235.  
  1236.